package wqh.controller.view;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import wqh.domain.UserRole;
import wqh.global.GlobalRole;
import wqh.global.GlobalSession;
import wqh.service.UserRoleService;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by devts on 2016/11/11.
 */

@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/view")
public class AllView {

    @Autowired
    private UserRoleService roleService;

    @RequestMapping("/index")
    public ModelAndView index(HttpServletRequest request)
    {
        ModelAndView m = new ModelAndView("ftl_1_0_index");
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","1-0");
        return m;
    }

    @RequestMapping("/fire_log")
    public ModelAndView fire_log(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_2_0_fire_log");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","2-0");
        return m;
    }

    @RequestMapping("/fault_log")
    public ModelAndView fault_log(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_2_1_fault_log");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","2-1");
        return m;
    }

    @RequestMapping("/false_log")
    public ModelAndView false_log(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_2_2_false_log");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","2-2");
        return m;
    }

    @RequestMapping("/map_show")
    public ModelAndView map_show(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_3_0_map_show");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","3-0");
        return m;
    }

    @RequestMapping("/device")
    public ModelAndView device(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_4_0_device");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","4-0");
        return m;
    }

    @RequestMapping("/map_config")
    public ModelAndView map_config(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_5_0_map_config");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","5-0");
        return m;
    }

    @RequestMapping("/sensor_type_config")
    public ModelAndView sensor_type_config(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_5_1_sensor_type_config");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","5-1");
        return m;
    }

    @RequestMapping("/monitor_config")
    public ModelAndView monitor_config(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_5_2_monitor_config");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","5-2");
        return m;
    }

    @RequestMapping("/monitor_pos")
    public ModelAndView monitor_pos(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_5_3_monitor_pos");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","5-3");
        return m;
    }

    @RequestMapping("/system_log")
    public ModelAndView system_log(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_6_0_system_log");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","6-0");
        return m;
    }

    @RequestMapping("/xls_io")
    public ModelAndView xls_io(HttpServletRequest request)
    {
        UserRole role = roleService.findByName(GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        int role_type = 0;
        if(role != null) role_type = role.getRole_auth_type_id();
        ModelAndView m = new ModelAndView("ftl_7_0_xls_io");
        m.addObject("role_type_id",role_type);
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("li_class","7-0");
        return m;
    }

    @RequestMapping("/user_manage")
    public ModelAndView user_manage(HttpServletRequest request)
    {
        String roleName = GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        UserRole role = roleService.findByName(roleName);
        ModelAndView m = new ModelAndView("ftl_8_0_user_manage");
        m.addObject("user_name", GlobalSession.getUserNameBySessionID(request.getSession().getId()));
        m.addObject("role_name", GlobalRole.getRoleNameByUserName(GlobalSession.getUserNameBySessionID(request.getSession().getId())));
        m.addObject("user_picture",request.getContextPath() + "/user_file/getPicture");
        m.addObject("role_name", roleName);
        if(role != null) m.addObject("role_id",role.getId());
        m.addObject("li_class","8-0");
        return m;
    }



}
